package main

import (
	"nearby/biz/handler"
	"nearby/biz/middleware"

	"github.com/gin-gonic/gin"
)

func register(r *gin.Engine) {
	r.Use(
		middleware.Auth(
			middleware.JwtDefaultClient,
			map[string]bool{
				"/nearby/ping":                    true,
				"/nearby/user_center/wx_login":    true,
				"/nearby/user_center/wx_register": true,
				"/nearby/moments":                 true,
				"/nearby/moment/:moment_id":       true,
				"/nearby/comments":                true,
			},
		),
	)

	r.GET("/nearby/ping", handler.Ping)

	// 用户中心
	r.POST("/nearby/user_center/wx_login", handler.WxLogin)
	r.POST("/nearby/user_center/wx_register", handler.WxRegister)
	r.DELETE("/nearby/user_center/:user_id", handler.DeleteUser)
	r.GET("/nearby/profile/me", handler.ProfileMe)

	// 帖子
	r.POST("/nearby/moment", handler.CreateMoment)
	r.GET("/nearby/moment/:moment_id", handler.GetMomentDetail, handler.ViewMomentDetail)
	r.GET("/nearby/moments", handler.GetMoments)
	r.DELETE("/nearby/moment", handler.DeleteMoment)

	// 评论
	r.POST("/nearby/comment", handler.CreateComment)
	r.GET("/nearby/comments", handler.GetComments)
	r.DELETE("/nearby/comment/:comment_id", handler.DeleteComment)

	// 点赞
	r.POST("/nearby/thumb_up", handler.ThumbUp)
	r.POST("/nearby/cancel_thumb_up", handler.CancelThumbUp)

	// 上传照片(单文件上传)
	r.POST("/nearby/upload_image", handler.UploadImage)
	// 上传照片(多文件上传)
	r.POST("/nearby/upload_images", handler.UploadImages)
}
